<template>
  <div class="logincontainer">
    <el-form ref="addModel" class="loginForm" :model="addModel" :rules="rules" :inline="false" size="small">
      <el-form-item label="">
        <span class="loginTitle">
          学生学籍管理系统
        </span>
      </el-form-item>
      <el-form-item prop="username">
        <el-input v-model="addModel.username" placeholder="请输入用账户" />
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="addModel.password" type="password" placeholder="请输入密码" />
      </el-form-item>
      <el-form-item prop="userType">
        <el-radio-group v-model="addModel.userType">
          <el-radio :label="2">学生</el-radio>
          <el-radio :label="3">教师</el-radio>
          <el-radio :label="1">管理员</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-row :gutter="20">
          <el-col :span="12" :offset="0">
            <el-button class="mybtn" type="primary" @click="onSubmit">登录</el-button>
          </el-col>
          <el-col :span="12" :offset="0">
            <el-button class="mybtn">取消</el-button>
          </el-col>
        </el-row>

      </el-form-item>
    </el-form>

  </div>
</template>

<script>
export default {
  data() {
    return {
      addModel: {
        username: 'mps',
        password: '123456',
        userType: ''
      },
      rules: {
        username: [{
          required: true,
          message: '请输入用户名称',
          trigge: 'blur'
        }],
        password: [{
          required: true,
          message: '请输入用户密码',
          trigge: 'blur'
        }],
        userType: [{
          type: 'number',
          required: true,
          message: '请选择用户类型',
          trigge: 'blur'
        }]
      }
    }
  },
  methods: {
    onSubmit() {
      this.$refs.addModel.validate((valid) => {
        if (valid) {
          this.$store.dispatch('user/login', this.addModel).then(() => {
            this.$router.push({ path: this.redirect || '/' })
            this.loading = false
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.logincontainer {
  height: 100%;
  background-color: #fff;
  background-image: url('../../assets/login_bg.png');
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: 100%;
  .loginForm {
    height: 350px;
    width: 450px;
    background: #fff;
    padding: 35px 20px;
    border-radius: 10px;
    .loginTitle {
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 24px;
      font-weight: 600;
      color: #409eff;
    }
    .mybtn {
      width: 100%;
    }
  }
}
</style>
